package com.atguigu.etlinterceptor;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

public class JsonTest {
    public static void main(String[] args) {
        Person person = new Person();
        person.setAge(18);
        person.setName("xiaowang");

        //把对象转换成json
        String json = JSON.toJSONString(person);
        System.out.println(json);

        //把json转换成jsonObject对象
        String json1 = "{\"age\":19,\"name\":\"aaa\"}";//属性名的双引号进行转译
        JSONObject jsonObject = JSON.parseObject(json1);
        String name1 = jsonObject.getString("name");
        Integer age1 = jsonObject.getInteger("age");
        System.out.println(name1+age1);

        //把json转成指定类型对象
        Person person1 = JSON.parseObject(json1, Person.class);
        System.out.println(person1);


    }
}

